package controller

import (
	"cn.pinming/gencode/core"
	"cn.pinming/gencode/core/controller"
	"time"
)

type GenTemplateController struct {
	controller.BaseController
}

func (this GenTemplateController) GetTemplate() []GenTemplate {
	query := "select * from gen_templat "
	countRow := core.DB.QueryRow("select count(*) from gen_templat ")
	if countRow != nil {
		var count int
		countRow.Scan(&count)
		core.Logger().Debugf("记录行数：%d", count)
	}
	rows, err := core.DB.Query(query+" limit ?", 4)
	var dataList = make([]GenTemplate, 0)
	if err != nil {
		core.Logger().Debugf("查询数据失败：v", err)
		return dataList
	}
	for rows.Next() {
		data := GenTemplate{}
		err2 := rows.Scan(&data.Id, &data.Name, &data.Version, &data.Create_time, &data.Create_user, &data.Update_time, &data.Update_user, &data.Url, &data.Config)
		core.Logger().Debugf("数据内容：%v", data)
		if err2 != nil {
			core.Logger().Debugf("数据内容获取失败：%v", err2)
		}
		dataList = append(dataList, data)
	}
	return dataList //this.ViewResult("gen/templates")
}

type GenTemplate struct {
	Id          string
	Name        string
	Version     string
	Create_time time.Time
	Create_user string
	Update_time time.Time
	Update_user string
	Url         string
	Config      string
}
